home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 3 / BBS in a box - Trilogy III.iso / Files / Prog / A / AE Sample (TC5) / Menus.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-07  |  3.2 KB  |  168 lines  |  [TEXT/KAHL]

  1. /* File: Menus.c */
  2.  
  3. #include    "AESimple.h"
  4.  
  5.  
  6. void SetItemEnable (MenuHandle theMenu, short theItem, Boolean enabled)
  7. {
  8.     if (enabled)
  9.         EnableItem(theMenu, theItem);
  10.     else
  11.         DisableItem(theMenu, theItem);
  12. } /* SetItemEnable */
  13.  
  14.  
  15. void EnableFileCommands (Boolean userWindow)
  16. {
  17.     MenuHandle    fileMenu = GetMHandle(kFileMenu);
  18.     WindowPtr    inFront = FrontWindow();
  19.     wiHand        info = 0L;
  20.     Boolean        hasPicture = FALSE;
  21.     
  22.     if (userWindow) {
  23.         info = (wiHand)GetWRefCon(inFront);
  24.         hasPicture = ((info != NIL) && ((*info)->thePicture != NIL));
  25.     }
  26.     SetItemEnable(fileMenu, cNew, !((inFront != NIL) && (((WindowPeek)inFront)->windowKind == dialogKind)));
  27.     SetItemEnable(fileMenu, cClose, (inFront != NIL) && (((WindowPeek)inFront)->goAwayFlag));
  28.     SetItemEnable(fileMenu, cPageSetup, hasPicture);
  29.     SetItemEnable(fileMenu, cPrint, hasPicture);
  30. } /* EnableFileCommands */
  31.  
  32.  
  33. void AdjustMenus()
  34. {
  35.     enum {
  36.             kNoWindows = 1,
  37.             kUsingDA,
  38.             kUsingDocWindow,
  39.             kUsingSpecialWindow
  40.         };
  41.  
  42.     WindowPtr    inFront = FrontWindow();
  43.     Boolean        isAUserWindow, isDeskAcc;
  44.     short        newMenuState;
  45.  
  46.     if (inFront == NIL) {
  47.         isAUserWindow = FALSE;
  48.         DisableItem(GetMHandle(kEditMenu), 0);
  49.         EnableFileCommands(FALSE);
  50.         newMenuState = kNoWindows;
  51.     } else {
  52.         if (isAUserWindow = isUserWindow(inFront)) {
  53.             EnableFileCommands(TRUE);
  54.             DisableItem(GetMHandle(kEditMenu), 0);
  55.             newMenuState = kUsingDocWindow;
  56.         } 
  57.         else if (isDeskAcc = ((WindowPeek)inFront)->windowKind < 0) {
  58.             EnableFileCommands(FALSE);
  59.             EnableItem(GetMHandle(kEditMenu), 0);
  60.             newMenuState = kUsingDA;
  61.         } else {
  62.                /* We have a window up front, but it's not a desk accessory or user window */
  63.             EnableFileCommands(FALSE);
  64.             newMenuState = kUsingSpecialWindow;
  65.         }
  66.     }
  67.     
  68.     if (newMenuState != gMenuState) {
  69.         DrawMenuBar();
  70.         gMenuState = newMenuState;
  71.     }
  72. } /* AdjustMenus */
  73.  
  74.  
  75.  
  76. void DoAppleCmds (short theItem)
  77. {
  78.     Str255        name;            /* string for DA name    */
  79.  
  80.     switch (theItem) {
  81.  
  82.         case cAbout: 
  83.             Alert(kAboutDialog, NIL);
  84.             break;
  85.             
  86.         default:
  87.             GetItem(GetMHandle(kAppleMenu), theItem, (StringPtr)&name);
  88.             OpenDeskAcc((StringPtr)&name);
  89.     }
  90. }
  91.  
  92.  
  93. void DoFileCmds (short theItem)
  94. {
  95.     long    result = 0;
  96.     FSSpec    theFile;
  97.     
  98.     switch (theItem) {
  99.  
  100.         case cNew: 
  101.             NewDisplayWindow();
  102.         break;
  103.         
  104.         case cOpen:
  105.             if (select_file(&theFile)) {
  106.                 NewDisplayWindow();
  107.                 open_selected_file(&theFile, FrontWindow());
  108.             }
  109.         break;
  110.                 
  111.         case cClose: 
  112.             CloseAWindow(FrontWindow());
  113.         break;
  114.  
  115.         case cPageSetup:
  116.             if (isUserWindow(FrontWindow()))
  117.                 ShowSetupDialog(FrontWindow());
  118.         break;
  119.  
  120.         case cPrint: 
  121.             if (isUserWindow(FrontWindow()))
  122.                 if (ShowJobDialog(FrontWindow()))
  123.                     PrintWindow(FrontWindow());
  124.         break;
  125.  
  126.         case cQuit: 
  127.             gDone = TRUE;
  128.     }
  129. } /* DoFileCmds */
  130.  
  131.  
  132. void DoDemoCmds (short theItem)
  133. {
  134.     switch (theItem) {
  135.     }
  136. } /* DoDemoCmds */
  137.  
  138.  
  139.  
  140.  
  141. void Dispatch (long menuResult)
  142. {
  143.     short     theMenu = (menuResult >> 16);                    /* menu selected    */
  144.     short     theItem = (menuResult & 0x0000FFFF);               /* item selected    */
  145.  
  146.     switch (theMenu) {
  147.  
  148.         case kAppleMenu: 
  149.             DoAppleCmds(theItem);
  150.             break;
  151.             
  152.         case kFileMenu: 
  153.             DoFileCmds(theItem);
  154.             break;
  155.             
  156.         case kEditMenu: 
  157.             SystemEdit(theItem - 1);
  158.             break;
  159.             
  160.         case kDemoMenu: 
  161.             DoDemoCmds(theItem);
  162.             break;
  163.             
  164.     }
  165.     HiliteMenu(0);               /* un-hilite selected menu */
  166. }
  167.  
  168.